<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:p="http://primefaces.org/ui"
      xmlns:f="http://java.sun.com/jsf/core">
    <h:head>
        <title>Tiendalia - Panel de usuario</title>
    </h:head>
    <h:body>
        <ui:composition template="template.xhtml">
            <ui:define name="content">
                <p:dataTable id="userTable" styleClass="adminTable" var="order" value="#{admUserBean.orders}">
                    <f:facet name="header">
                        <h:outputText styleClass="headerTitle" value="#{admUserBean.user.firstname} #{admUserBean.user.lastname}" />
                        <p:commandLink onclick="userDeletionDialog.show();">
                            <p:graphicImage styleClass="imgBtn imgBtnDelete" url="resources/images/delete.png" alt="Darse de baja" title="Darse de baja" />
                        </p:commandLink>
                        <p:commandLink onclick="panel.toggle()">
                            <p:graphicImage styleClass="imgBtn" url="resources/images/editUser.png" alt="Editar datos personales" title="Editar datos personales" />
                        </p:commandLink>
                        <p:panel id="pnl" collapsed="true" toggleable="true" widgetVar="panel" >
                            <h:form id="userEditForm" styleClass="editForm">
                                <h:outputLabel styleClass="title" value="Datos personales:"/>
                                <p:messages id="editUserMessages" autoUpdate="true"/>
                                <p:panelGrid columns="2" columnClasses="editLabel, editValue">

                                    <p:outputLabel value="E-mail: " for="editEmail" />
                                    <p:inputText id="editEmail" value="#{admUserBean.user.email}" disabled="true"/>

                                    <p:outputLabel value="Nombre: " for="editFirstName" />
                                    <p:inputText id="editFirstName" value="#{admUserBean.user.firstname}" />

                                    <p:outputLabel value="Apellidos: " for="editLastName" />
                                    <p:inputText id="editLastName" value="#{admUserBean.user.lastname}" />

                                    <p:outputLabel for="newPassword1" value="Nueva contraseña: " />
                                    <p:password id="newPassword1" value="#{admUserBean.newPassword}" match="newPassword2" label="Password"
                                                weakLabel="Débil" validatorMessage="Las nuevas contraseñas no coinciden" feedback="true"
                                                strongLabel="Excelente" goodLabel="Buena" promptLabel="Introduce tu contraseña"/>

                                    <p:outputLabel for="newPassword2" value="Repite contraseña: " />
                                    <p:password id="newPassword2" value="#{admUserBean.newPassword2}" label="Password 2"/>

                                    <p:outputLabel value="Antigua contraseña: " for="oldPassword" />
                                    <p:password id="oldPassword" value="#{admUserBean.oldPassword}" required="true"/>

                                </p:panelGrid>
                                <p:commandButton value="Guardar cambios" action="#{admUserBean.editUser()}" oncomplete="panel.toggle();" update=":userTable, editUserMessages"/>
                            </h:form>
                        </p:panel>
                    </f:facet>
                    <p:column style="width:2%">
                        <p:rowToggler />
                    </p:column>
                    <p:column headerText="Código Pedido">
                        <h:outputText value="#{order.id}" />
                    </p:column>
                    <p:column headerText="Fecha">
                        <h:outputText value="#{order.orderDate}">
                            <f:convertDateTime type="both" locale="es_ES" pattern="dd/MM/yyyy HH:mm:ss" timeZone="GMT+2" />
                        </h:outputText>
                    </p:column>
                    <p:column headerText="Importe">
                        <h:outputText value="#{order.total}" >
                            <f:convertNumber currencySymbol="€" type="currency" />
                        </h:outputText>
                    </p:column>
                    <p:rowExpansion>
                        <p:dataTable id="prodsTable" styleClass="detailTable" var="product" value="#{order.orderProducts}">
                            <f:facet name="header">
                                <h:outputText styleClass="headerTitle" value="Detalle de pedido ##{order.id}" />
                            </f:facet>
                            <p:column headerText="Nombre">
                                <h:outputText value="#{product.item.name}" />
                            </p:column>
                            <p:column headerText="Cantidad">
                                <h:outputText value="#{product.quantity}" />
                            </p:column>
                            <p:column headerText="Precio">
                                <h:outputText value="#{product.purchasePrice}" >
                                    <f:convertNumber currencySymbol="€" type="currency" />
                                </h:outputText>
                            </p:column>
                            <p:column headerText="Total">
                                <h:outputText value="#{product.total}">
                                    <f:convertNumber currencySymbol="€" type="currency" />
                                </h:outputText>
                            </p:column>
                        </p:dataTable>
                    </p:rowExpansion>
                </p:dataTable>
                <h:form id="userDeletionForm">
                    <p:confirmDialog id="userDeletionDialog" message="Si te das de baja, no podrás volver a registrar este e-mail."
                                     header="Confirmar baja" severity="alert" widgetVar="userDeletionDialog">
                        <p:commandButton id="decline" value="No " onclick="userDeletionDialog.hide();" type="button" />
                        <p:commandButton id="confirm" value="Sí" oncomplete="userDeletionDialog.hide();"
                                         action="#{admUserBean.disableUser}" />
                    </p:confirmDialog>
                </h:form>
            </ui:define>
        </ui:composition>
    </h:body>
</html>